<template>
  <div class="app-container">
    <p class="pinformation">搜索条件</p>
    <el-form :model="queryParams" ref="queryRef" label-width="80">
      <el-row>
        <el-col :span="3">
          <el-form-item label="方案编号：" prop="projectCode">
            <el-input clearable maxlength="100" v-model="queryParams.projectCode" placeholder="请输入方案编号"
              @keyup.enter="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="方案名称：" prop="projectName">
            <el-input clearable maxlength="100" v-model="queryParams.projectName" placeholder="请输入方案名称"
              @keyup.enter="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="受检单位：" prop="sjCustomName">
            <el-input clearable maxlength="100" v-model="queryParams.sjCustomName" placeholder="请输入受检单位"
              @keyup.enter="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="委托单位：" prop="wtCustomName">
            <el-input clearable maxlength="100" v-model="queryParams.wtCustomName" placeholder="请输入委托单位"
              @keyup.enter="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="方案开始时间：" label-width="110">
            <el-date-picker v-model="dateRange" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
              start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="紧急状态：" prop="degree">
            <el-select clearable v-model="queryParams.degree" filterable>
              <el-option v-for="dict in proxy.addListNoLimit(sys_degree)" :key="dict.value" :label="dict.label"
                :value="parseInt(dict.value)" />
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="2">
          <el-row justify="center">
            <el-button type="success" @click="handleQuery">搜索</el-button>
            <el-button class="resetBtn" @click="resetQuery">重置</el-button>
          </el-row>
        </el-col>
      </el-row>
    </el-form>
    <el-row style="margin-bottom: 5px">
      <p class="pinformation">方案列表</p>
      <p class="totalStyle">共 {{ total }} 条数据</p>
    </el-row>
    <el-table :data="projectList" ref="projectTableRef" v-loading="loading">
      <el-table-column label="方案编号" align="center" prop="projectCode" />
      <el-table-column label="方案名称" align="center" prop="projectName" />
      <el-table-column label="受检单位" align="center" prop="sjCustomName" />
      <el-table-column label="委托单位" align="center" prop="wtCustomName" />
      <el-table-column label="方案开始时间" align="center" prop="planDate" />
      <el-table-column label="要求完成时间" align="center" prop="endTime" />
      <el-table-column label="方案类型" align="center" prop="contractType">
        <template #default="scope">
          <dict-tag :options="sys_contract_type" :value="scope.row.contractType" />
        </template>
      </el-table-column>
      <el-table-column label="采样员" align="center" prop="cyUserName" />
      <el-table-column label="操作" align="center" fixed="right">
        <template #default="scope">
          <el-button link type="success" v-if="queryParams.userStatus == 0" @click="goFilling(scope.row,'62c25e13e4b00285a21ce046')">审核</el-button>
          <el-button link type="success" v-if="queryParams.userStatus == 1" @click="goFilling(scope.row,'62c25e13e4b00285a21ce047')">审核记录</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script setup name="LocalWrite">
import { getLocalWriteList } from "@/api/cyCheck/localWrite";
const router = useRouter();
const { proxy } = getCurrentInstance();
const { sys_degree } = proxy.useDict("sys_degree");
const {
  sys_contract_type,
} = proxy.useOrgDict(
  "sys_contract_type",
);
const projectList = ref([]);
const dateRange = ref([]);
const loading = ref(false);
const total = ref(0);
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    degree: -1
  },
  rules: {
    // useCount: [{ required: true, message: "本次使用量不能为空", trigger: "blur" },]
  },
});

const { queryParams, rules } = toRefs(data);

const props = defineProps({
  userStepId: {
    type: Number, //参数类型
  },
  userStatus: {
    type: Number, //参数类型
  },
});

function getList() {
  loading.value = true
  queryParams.value.userStepId = props.userStepId;
  queryParams.value.userStatus = props.userStatus;
  getLocalWriteList(
    proxy.addDateRange(queryParams.value, dateRange.value)
  ).then((res) => {
    projectList.value = res.rows;
    total.value = res.total;
    loading.value = false
  });
}
function handleQuery() {
  getList();
}
function resetQuery() {
  queryParams.value.pageNum = 1;
  proxy.resetForm("queryRef");
  dateRange.value = [];
  getList();
}

function goFilling(row,status) {
  router.push({
    path: "/cyCheck/cyFlilling",
    query: { primaryId: row.projectId, status: status },
  });
}

getList();

watch(
  () => total.value,
  () => {
    if (total.value) {
      heightParams.value = [{ tableName: "project", bottomHeight: 83 }];
    } else {
      heightParams.value = [{ tableName: "project", bottomHeight: 31 }];
    }
    getTableHeight();
  }
);

const heightParams = ref([{ tableName: "project", bottomHeight: 31 }]);

function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}
onMounted(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
})
onUpdated(() => {
  nextTick(function () {
    getTableHeight();
  });
});
onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});
</script>

<style></style>
